<!-- @format -->

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<style>
			input {
				width: 200px;
				transition: all 0.3s;
			}

			/* focus伪类选择器  获得焦点 */
			input:focus {
				width: 300px;
			}
		</style>
	</head>

	<body>
		<input type="text" />
		<!-- 分别用CSS和JS的方式实现：输入框获得焦点，就将其宽度变为300px -->
		<script>
			const input = document.querySelector("input");
			input.addEventListener("focus", function () {
				input.style.width = "300px";
			});
		</script>
	</body>
</html>
